]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[gnome-shell.in] When we don't have DISPLAY, attempt to pull in running session
authorColin Walters <walters@verbum.org>
Thu, 25 Feb 2010 18:35:32 +0000 (13:35 -0500)
committerColin Walters <walters@verbum.org>
Thu, 25 Feb 2010 19:46:27 +0000 (14:46 -0500)
This is a convenience for debugging when logging in over ssh.  Longer term
we should stick this code (in a more OS portable fashion) into ConsoleKit.

src/gnome-shell.in [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 254cdee..36548c5
@@ -14,6 +14,50 @@ import termios
 import time
 import errno
 
+def get_running_session_environs():
+    wanted_environment = ['DBUS_SESSION_BUS_ADDRESS', 'DISPLAY', 'XDG_DATA_DIRS',
+                          'XAUTHORITY', 'XDG_SESSION_COOKIE', 'ORBIT_SOCKETDIR',
+                          'SESSION_MANAGER']
+    num_re = re.compile('^[0-9]+$')
+    myuid = os.getuid()
+    if not os.path.isdir('/proc'):
+        return {}
+    for filename in os.listdir('/proc'):
+        if not num_re.match(filename):
+            continue
+        piddir = '/proc/' + filename
+        try:
+            stat = os.stat(piddir)
+        except OSError, e:
+            continue
+        if not stat.st_uid == myuid:
+            continue
+        try:
+            exe = os.readlink(piddir + '/exe')
+        except OSError, e:
+            continue
+        if os.path.basename(exe) != 'gnome-session':
+            continue
+        try:
+            f = open(os.path.join(piddir, 'environ'))
+        except OSError, e:
+            continue
+        environ_data = f.read()
+        f.close()
+        # There's a trailing null at the last one, so remove the
+        # empty string
+        environs = environ_data.split('\0')[:-1]
+        # Rumor has it the presence of just FOO (instead of FOO=bar)
+        # represents a deleted environment variable
+        environs = filter(lambda x: '=' in x, environs)
+        # Turn it into a dictionary
+        environs = dict(map(lambda x: x.split('=', 1), environs))
+        result = {}
+        for key in wanted_environment:
+            if key in environs:
+                result[key] = environs[key]
+        return result
+
 def start_xephyr():
     tmpdir = tempfile.mkdtemp("", "gnome-shell.")
     atexit.register(shutil.rmtree, tmpdir)
@@ -343,6 +387,12 @@ else:
 if options.verbose:
     print "Starting shell"
 
+
+# Handle ssh logins
+if 'DISPLAY' not in os.environ:
+    running_env = get_running_session_environs()
+    os.environ.update(running_env)
+
 if options.debug:
     # Record initial terminal state so we can reset it to that
     # later, in case we kill gdb at a bad time